package info.yaohua;

import info.dao.Ac01Dao;
import info.util.SessionNull;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class Check_Xs_Servlet extends HttpServlet
	{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
		{
			// TODO Auto-generated method stub
			HttpSession session=req.getSession(false);
			if(session==null)
				{
					SessionNull.forwordTo(req, resp);
				}
			else
				{
					String username = req.getParameter("username");
					Ac01Dao ac01Dao=new Ac01Dao();
					try
						{
							boolean success=ac01Dao.findUserByUsername(username);
							if(success)
								{
									PrintWriter write=resp.getWriter();
									write.println(0);
								}
							else
								{
									PrintWriter write=resp.getWriter();
									write.println(1);
								}
						}
					catch (NamingException | SQLException e)
						{
							// TODO Auto-generated catch block
							e.printStackTrace();
						} 
				}
		}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
		{
			// TODO Auto-generated method stub
			super.doPost(req, resp);
		}
		
	}
